package net.oschina.app.adapter.me.messageAdapter;

import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import net.oschina.app.R;
import net.oschina.app.base.BaseListAdapter;
import net.oschina.app.base.Global;
import net.oschina.app.bean2.PraiseBean;
import net.oschina.app.ui.activity.DetailActivity;

/**
 * Created by Shinelon on 2017/1/15.
 */

public class PraiseMeListAdapter extends BaseListAdapter<PraiseBean.MytweetBean> {
    private String mUrl;
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(Global.mContext).inflate(R.layout.item_me_message_praiseme,parent,false);
        PraiseMeHolder holder = new PraiseMeHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        PraiseBean.MytweetBean data =  mList.get(position);
        ((PraiseMeHolder)holder).tvName.setText(data.getUser().getName());
        ((PraiseMeHolder)holder).tvAuthor.setText(data.getTweet().getAuthor());
        ((PraiseMeHolder)holder).tvData.setText(data.getDatatime());
        ((PraiseMeHolder)holder).tvBody.setText(data.getTweet().getBody());
        mUrl = data.getUser().getPortrait();
    }

    class PraiseMeHolder extends RecyclerView.ViewHolder{
        public TextView tvName;
        public TextView tvData;
        public TextView tvBody;
        public TextView tvAuthor;
        public PraiseMeHolder(View itemView) {
            super(itemView);
            tvName = (TextView) itemView.findViewById(R.id.tv_praise_name);
            tvBody = (TextView) itemView.findViewById(R.id.tv_praise_body);
            tvAuthor = (TextView) itemView.findViewById(R.id.tv_praise_author);
            tvData = (TextView) itemView.findViewById(R.id.tv_praise_data);
            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(Global.mContext, DetailActivity.class);
                    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    intent.putExtra("url",mUrl);
                    Global.mContext.startActivity(intent);
                }
            });
        }
    }
}
